<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2018/6/13
 * Time: 15:50
 */
namespace app\common\model;
use think\Model;

class User extends Model {
    protected $table='up_u_user';

    public function checkToken($token){
        $map['user_token'] = array('eq',$token);
        $uid = $this->where($map)->value('user_id');
        if($uid){
            return $uid;
        }else{
            return $this->_error[2010];
        }
    }
    /**
     * @param $uid
     * 搜索用户是否存在
     */
    public function selectUser($uid){
        $model = self::instance();
        $list = $model->where('user_id',$uid)->value('user_id');
        return $list;
    }
    
    /**
     * 判断用户是否认证
     * @param $user_id
     * @return mixed
     */
    public function isAttestation($user_id){
        $model = self::instance();
        $attestation = $model->where('user_id', $user_id)->value('user_attestation');
        return $attestation;
    }
    
    /**
     * @param $areaID 消息发布时选择的省/市ID
     * @param $field  用户表中的省/市ID
     * @return array
     */
    public function getPushUser($field = '', $areaID = ''){
        if($field != '' && $areaID != ''){
            $user_ids = $this->where($field, $areaID)->column('user_id');
        }else{
            $user_ids = $this->column('user_id');
        }
        return $user_ids;
    }
    /**
     * @param $id 根据ID编号获取一条信息
     * @return mixed 具体的信息条目
     */
    public function getOne($id){
        $model = self::instance();
        return $model->where(array('user_id'=>array('eq',$id)))->value('user_id');
    }
    private static $instance;
    public static function instance()
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}